package com.example.project;

import java.util.ArrayList;
import java.util.HashMap;

import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;


public class ValAdapter extends BaseAdapter {
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    GPSTracker gps;
    
    public ValAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }
    
    public GeoPoint getPoint(int position){
    	GeoPoint point1 = new GeoPoint((int)(Float.parseFloat(data.get(position).get(Menjar.KEY_LATITUD))* 1E6), (int) (Float.parseFloat(data.get(position).get(Menjar.KEY_LONGITUD))* 1E6));
    	return point1;
    }

    public Object getItem(int position) {
    	GeoPoint point1 = new GeoPoint((int)(Float.parseFloat(data.get(position).get(Menjar.KEY_LATITUD))), (int) (Float.parseFloat(data.get(position).get(Menjar.KEY_LONGITUD))));
    	return point1;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_rowval, null);

        //TextView title = (TextView)vi.findViewById(R.id.title); // title
        TextView coment = (TextView)vi.findViewById(R.id.editText1);
        RatingBar qual = (RatingBar)vi.findViewById(R.id.ratingBar1);
        
        //ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
        
        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);
        gps = new GPSTracker(parent.getContext());
        // Setting all values in listview
       coment.setText(song.get("comentari"));
       
        qual.setRating(Float.parseFloat(song.get("nota")));
       
    
        return vi;
    }

}
